//
//  WXChangeCarTyeViewController.m
//  CarJX
//
//  Created by xcq on 14-9-29.
//  Copyright (c) 2014年 KK. All rights reserved.
//

#import "WXChangeCarTyeViewController.h"
#define kCell @"cell"

@interface WXChangeCarTyeViewController () <UITableViewDataSource,UITableViewDelegate>

@end

@implementation WXChangeCarTyeViewController


- (void) dismissMainPage{
    [self dismissViewControllerAnimated:YES completion:nil];
}

 - (void)viewDidLoad
{
    [self setTitle:@"车牌地选择"];

    [self showNavBarWithRightTitle:nil andRightAction:nil andLeftAction:@selector(dismissMainPage) andCustom:NO];
    
    [super viewDidLoad];
    if (provinces == nil) {
        provinces = [[NSMutableArray alloc] initWithObjects:@"北京",
                     @"天津",
                     @"河北",
                     @"山西",
                     @"内蒙古",
                     @"辽宁",
                     @"吉林",
                     @"黑龙江",
                     @"上海",
                     @"江苏",
                     @"浙江",
                     @"安微",
                     @"福建",
                     @"江西",
                     @"山东",
                     @"河南",
                     @"湖北",
                     @"湖南",
                     @"广东",
                     @"广西",
                     @"海南",
                     @"重庆",
                     @"四川",
                     @"贵州",
                     @"云南",
                     @"西藏",
                     @"陕西",
                     @"甘肃",
                     @"青海",
                     @"宁夏",
                     @"新疆",
                     @"台湾", nil];
    }
    if (shorthand == nil) {
        shorthand = [[NSMutableArray alloc] initWithObjects:@"京",
                     @"津",
                     @"冀",
                     @"晋",
                     @"蒙",
                     @"辽",
                     @"吉",
                     @"黑",
                     @"沪",
                     @"苏",
                     @"浙",
                     @"皖",
                     @"闽",
                     @"赣",
                     @"鲁",
                     @"豫",
                     @"鄂",
                     @"湘",
                     @"粤",
                     @"桂",
                     @"琼",
                     @"渝",
                     @"川",
                     @"贵",
                     @"云",
                     @"藏",
                     @"陕",
                     @"甘",
                     @"青",
                     @"宁",
                     @"新",
                     @"台",
                     nil];
    }
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource =self;
    [self.view addSubview:self.tableView];
    [self.tableView reloadData];
     
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell {
    [cell setSelectionStyle:UITableViewCellSelectionStyleGray];
 }

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCell ];
    
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kCell];
    }
    
    cell.textLabel.text = [shorthand objectAtIndex:indexPath.row];
    cell.detailTextLabel.text = [provinces objectAtIndex:indexPath.row];
    
    return cell;
    
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    seleteKey = cell.textLabel.text;

    self.callBack(seleteKey);
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (NSString *) returnKey{
        return seleteKey;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
     // Return the number of rows in the section.
    return [provinces count];
}


@end
